package com.glc.gao.gavin.rxjavademo.operator;

import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class TimerActivity extends BaseActivity {

    @Override
    public int getDescribeText() {
        return R.string.describe_timer;
    }

    @Override
    protected int getContextView() {
        return R.layout.activity_timer;
    }

    public void executeTimer(View view) {
        print("timer start:" + System.currentTimeMillis());

        Observable.timer(2, TimeUnit.SECONDS).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        print("timer " + aLong + " execute at :" + System.currentTimeMillis());
                    }
                });
    }
}
